{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "708c6a80",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "insert之后的names： ['Mike', 'yougege', 'Mary', 'Jan', 'Jack']\n",
      "0\n",
      "names的长度/names的列表元素个数： 5\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "# Author: Zhichao\n",
    "# Date: week06\n",
    "\n",
    "\n",
    "stu_id = [10001,10002,10003,10004,10008,10001,10009,10010,10001]\n",
    "# 思考，如何取出所有位置10001的index？\n",
    "names = [\"Mike\", \"Mary\", \"Jan\", \"Jack\"]\n",
    "\n",
    "# 列表的私有方法\n",
    "\n",
    "# 1.增加的方法\n",
    "## 1.1 增加 append()  增加在list的末尾\n",
    "# names.append(1)\n",
    "# print(names)\n",
    "\n",
    "## 1.2 插入 insert() 可以指定位置增加元素\n",
    "names.insert(1,'yougege')\n",
    "print(\"insert之后的names：\",names)\n",
    "\n",
    "# 2. 删除 remove  和 pop\n",
    "## 优势：如果删除list中多个元素时，remove比较合适\n",
    "##\n",
    "\"\"\"\n",
    "Remove first occurrence of value.\n",
    "Raises ValueError if the value is not present.\n",
    "\"\"\"\n",
    "## 2.1 remove()一般情况下 使用remove先用in做判断\n",
    "# if 10001 in names:\n",
    "#     names.remove(10001)\n",
    "# print(\"remove删除的结果：\",names)\n",
    "\n",
    "\n",
    "## 2.2 pop() 删除位置为1的这个元素\n",
    "# names.pop(-1)\n",
    "# print(\"pop()方法后的names:\",names)\n",
    "\n",
    "\n",
    "## 3. index()索引 查看该元素如10001 在stu_id中第一个出现的位置索引\n",
    "print(stu_id.index(10001))\n",
    "\n",
    "## 4. clear()清除所有数据\n",
    "# names.clear()\n",
    "# print(\"清除names列表后的值：\",names)\n",
    "\n",
    "## 5.count()查看列表元素出现的个数，（简单应用）统计分数出现的次数\n",
    "# print(\"count方法的结果:\",stu_id.count(10001))\n",
    "# print(names)\n",
    "\n",
    "## 6. extend() 是给指定的list进行扩充\n",
    "# names.extend(stu_id)\n",
    "# print(names)\n",
    "\n",
    "## 作业： list方法的总结，list的切片的总结\n",
    "\n",
    "\n",
    "# 列表的其他方法(Sequence Types 的一些方法)\n",
    "## 1. len()查看list长度\n",
    "print(\"names的长度/names的列表元素个数：\",len(names))\n",
    "## 2. in 查看元素是否存在list当中,结果为布尔值，False/True,\n",
    "##    一般在操作list的修改和删除时会先判断\n",
    "print(\"zhichao\" in names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fd4fdbac",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
